package com.lhweb.springsecurity.web.controller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.ModelAttribute;


/**
 * The base Spring MVC controller. Used to provide common functionality to all controllers.
 * 
 * @author Mularien
 */
public class BaseController {
	
	protected Authentication getAuthentication(){
		return SecurityContextHolder.getContext().getAuthentication();
	}
	
	//判断是否拥有Role_user权限来显示登陆链接
	@ModelAttribute("showLoginLink")
	public boolean getShowLoginLink(){
		for(GrantedAuthority authority:getAuthentication().getAuthorities()){
			if(authority.getAuthority().equals("ROLE_USER")){
				return false;
			}
		}
		return true;
	}
}
